#define DEBUG
#include <cstdio>
#define MAXN 50000

using namespace std;

void go(int s, int x, bool *book, int *a, int *l, int *r, int n) {
  static int que[MAXN+1];
  for (int i=1; i<=n; i++) {
    book[i] = false;
  }
  int h=0, t=0;
  if (x!=s) {
    book[s] = true;
    que[++t] = s;
  }

  for (; h<t; ) {
    h++;
    for (int i=que[h]+1; i<=n; i++) {
      if (a[i]>=l[que[h]] && a[i]<=r[que[h]] &&  i!=x && !book[i]) {
	book[i] = true;
	que[++t] = i;
      }
    }
  }
}

int main() {
#ifdef DEBUG
  freopen("2.in", "r", stdin);
  freopen("2.out", "w", stdout);
#endif

  static int a[MAXN+1], l[MAXN+1], r[MAXN+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
  }
  for (int i=1; i<=n; i++) {
    scanf("%d %d", l+i, r+i);
  }

  static int ans[MAXN+1];
  static bool book[MAXN+1];
  for (int i=1; i<=n; i++) {
    go(1, i, book, a, l, r, n);
    for (int j=1; j<=n; j++) {
      ans[j] += !book[j];
    }
  } 
  go(1, 0, book, a, l, r, n);

  for (int i=1; i<=n; i++) {
    if (book[i]) {
      printf("%d\n", ans[i]);
    } else {
      printf("-1\n");
    }
  }

  fcloseall();
  return 0;
}
